class Solution {
    public void duplicateZeros(int[] arr) {
        int cur = 0;
        int dest = -1;
        int len = arr.length;
        while(cur < len) {
            if(arr[cur] == 0) {
                dest += 2;
            } else {
                dest ++;
            }
            if(dest >= len - 1) {
                break;
            }
            cur++;
        }
        // 判定是否需要覆写
        if(cur >= len - 1) {
            return;
        }
        // 处理特殊情况
        if(dest >= len) {
            arr[len - 1] = 0;
            dest -= 2;
            cur -= 1;
        }
        // 覆写
        while(cur >= 0) {
            if(arr[cur] == 0) {
                arr[dest--] = 0;
                arr[dest--] = 0;
                cur--;
            } else {
                arr[dest--] = arr[cur--];
            }
        }
    }

    public boolean isHappy(int n) {
        int fast = fun(fun(n));
        int slow = fun(n);
        while(fast != 1) {
            fast = fun(fun(fast));
            slow = fun(slow);
            if(fast == slow) {
                break;
            }
        }
        if(fast == 1) {
            return true;
        } else {
            return false;
        }
    }
    public int fun(int n) {
        int sum = 0;
        while(n > 0) {
            sum += (n % 10) * (n % 10);
            n /= 10;
        }
        return sum;
    }

    public int maxArea(int[] height) {
        int len = height.length;
        int left = 0;
        int right = len - 1;
        int max = 0;
        while(left < right) {
            int high = height[left] < height[right] ? height[left] : height[right];
            int width = right - left;
            if(high * width > max) {
                max = high * width;
            }
            if(high == height[left]) {
                left++;
            } else {
                right--;
            }
        }
        return max;
    }
}